package com.songlanyun.modules.faq.controller.admin;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.faq.entity.SysFaqEntity;
import com.songlanyun.modules.faq.service.SysFaqService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 常见问题
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2020-12-30 16:30:06
 */
@RestController
@RequestMapping("admin/sys/faq")
public class SysFaqAdminController extends AbstractController {
    @Autowired
    private SysFaqService sysFaqService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("faq:sysfaq:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = sysFaqService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("faq:sysfaq:info")
    public R info(@PathVariable("id") Integer id) {
        SysFaqEntity sysFaq = sysFaqService.getById(id);

        return R.ok().put("data", sysFaq);
    }

    /**
     * 保存
     */
    @SysLog("保存常见问题")
    @PostMapping("/save")
    //@RequiresPermissions("faq:sysfaq:save")
    public R save(@RequestBody SysFaqEntity sysFaq) {
        verifyAdmin();
        ValidatorUtils.validateEntity(sysFaq);

        sysFaqService.save(sysFaq);
        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改常见问题")
    @PutMapping("/update")
    //@RequiresPermissions("faq:sysfaq:update")
    public R update(@RequestBody SysFaqEntity sysFaq) {
        verifyAdmin();
        ValidatorUtils.validateEntity(sysFaq);

        sysFaqService.updateById(sysFaq);
        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除常见问题")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("faq:sysfaq:delete")
    public R delete(@PathVariable("id") Integer id) {
        verifyAdmin();
        sysFaqService.removeById(id);

        return R.ok();
    }

}
